package com.group9.handinhand.dao.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.apache.commons.lang.ArrayUtils;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.RequestResponseSO;

@Entity
@Table(name = "REQUEST_RESPONSE")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class RequestResponse extends AbstractBaseModel {

	private static final long serialVersionUID = 1L;

	@ManyToOne
	@JoinColumn(name = "USER_ID", nullable = false)
	private User user;
	
	@ManyToOne
	@JoinColumn(name = "REQUEST_ID", nullable = false)
	private Request request;
	
	@Column(name = "RESPOND_AMOUNT", nullable = false)
	private int respondAmount;
	
	public RequestResponseSO convertToServiceObject(String... ignoreProperties) {
		RequestResponseSO so = (RequestResponseSO) convert(new RequestResponseSO(), 
			(String[]) ArrayUtils.addAll(ignoreProperties, new String[]{"request","user"}));
		so.setRequest(request.convertToServiceObject(new String[]{"moderators", "posts"}));
		so.setUser(user.convertToServiceObject(new String[]{"socialUsers"}));
		return so;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Request getRequest() {
		return request;
	}

	public void setRequest(Request request) {
		this.request = request;
	}

	public int getRespondAmount() {
		return respondAmount;
	}

	public void setRespondAmount(int respondAmount) {
		this.respondAmount = respondAmount;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	@Override
	public String toString() {
		return "RequestResponse [user=" + user + ", request=" + request
				+ ", respondAmount=" + respondAmount + "]";
	}
	
	
	
}
